package Song.Han.Demo03;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/*
    文件复制联系
    数据源：E:\IDeaProject\Day14\src\Song\Han\Demo01\证件照.png
    目的地：E:\IDeaProject\Day14\src\Song\Han\Demo03\证件照.png
*/
public class Demo01Copy {
    public static void main(String[] args) throws IOException {

        long s = System.currentTimeMillis();

        FileInputStream fis = new FileInputStream("E:\\IDeaProject\\Day14\\src\\Song\\Han\\Demo01\\证件照.png");
        FileOutputStream fos = new FileOutputStream("E:\\IDeaProject\\Day14\\src\\Song\\Han\\Demo03\\证件照.png");

/*
        //63ms
        //一个字节一个字节太慢，用字节数组缓冲，读写多个字节
        int len = 0;
        while ((len = fis.read()) != -1){
            fos.write(len);
        }
*/

        //1ms
        byte[] bytes = new byte[1024];
        int len = 0;
        while ((len = fis.read(bytes)) != -1){
            fos.write(bytes,0,len);
        }

        //先关写，后关读
        fos.close();
        fis.close();

        long e = System.currentTimeMillis();
        System.out.println(e-s);
    }
}
